import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'
import './assets/css/global.css'
import './assets/fonts/iconfont.css'
import TreeTable from 'vue-table-with-tree-grid'


import VueQuillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'

Vue.use(VueQuillEditor, /* { default global options } */ )

import Nprogress from 'nprogress'
import 'nprogress/nprogress.css'


import axios from 'axios'

// 配置请求的根路径
// axios.defaults.baseURL = 'http://127.0.0.1:9102/api/private/v1/';
axios.defaults.baseURL = '/vueapi';

// axios拦截器，添加token头部信息
// 在request拦截器中，展示进度条 
axios.interceptors.request.use(config => {

    // 在request拦截器中，展示进度条
    Nprogress.start()
    config.headers.Authorization = window.sessionStorage.getItem('token');
    // console.log(config)

    return config
})

// 在response拦截器中，隐藏进度条
axios.interceptors.response.use(config => {

    Nprogress.done()

    return config
})


Vue.prototype.$http = axios;

Vue.config.productionTip = false

// 注册第三方 vuetable组件
Vue.component('tree-table', TreeTable)

// 注册全局过滤器 (时间格式转换)
// (过滤器名称，回调函数（原始值）)
Vue.filter('dateFormat', function(originValue) {

    const date = new Date(originValue)

    const year = date.getFullYear();
    // 字符串补0，padStart（一共多少位，补什么字符）
    const month = (date.getMonth() + 1 + '').padStart(2, '0')
    const day = (date.getDate() + '').padStart(2, '0')

    const hour = (date.getHours() + '').padStart(2, '0')
    const minute = (date.getMinutes() + '').padStart(2, '0')
    const second = (date.getSeconds() + '').padStart(2, '0')


    return `${year}-${month}-${day} ${hour}:${minute}:${second}`


})

new Vue({
    router,
    render: h => h(App)
}).$mount('#app')
